package org.opensourcephysics.stp.neto;//Particle falling under gravity by Verlet

public class VerletAlgoritmo {
    public static void main(String args[]) {

        // Initialise some variables
        double force = -9.8;
        double mass = 1.0;
        double dt = 0.1;
        double height = 30;
        double vtemp = 0.0;
        double velo = 0.0;
        double accn = 0.0;
        double time = 0.0;
        double nsteps = 10 / dt;

        // Loop over time, nsteps*dt, using Verlet algorithm

        for (double i = 1; i < nsteps; i++) {
            height = height + velo * dt + accn * dt * dt / 2.0;
            vtemp = velo + accn * dt / 2.0;
            accn = force / mass;
            velo = vtemp + accn * dt / 2.0;
            time = time + dt;
//  Implement elastic bouncing condition
            if (height < 0.0) {
                height = -height;
                velo = -velo;
            }
            System.out.println(time + " " + height);
        }
    }
}
